import requests


class RequestsSpider():

    def __init__(self):
        url = "http://www.baidu.com/"
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36"
        }
        self.response = requests.get(url, headers=header)

    def run(self):
        data = self.response.content.decode('utf-8')

        # 获取请求头
        print(self.response.request.headers)

        # 获取响应头
        print(self.response.headers)

        # 获取响应码
        print(self.response.status_code)

        # 获取请求cookie
        print(self.response.request._cookies)

        # 获取响应cookie
        print(self.response.cookies)


res = RequestsSpider()
res.run()
